package obecto.utility.observe
{
	import flash.events.Event;
	
	[Event(name="handler", type="flash.events.Event")]
	public class When extends ObserveValue
	{
		private var _expression : Object;
		
		public function When() : void
		{
			super.value = true;
		}
		
		public function set expression(value : Object): void
		{
			super.source = value;
		}
		
		public function get expression(): Object
		{
			return super.source;
		}
						
		override public function addEventListener(type : String, listener : Function, 
			useCapture : Boolean = false, priority : int = 0, useWeakReference : Boolean = false) : void
		{
			if(type == "handler")
			{
				super.handler = function() : void { listener(null) };
			}
			else
			{
				super.addEventListener(type, listener, useCapture, priority, useWeakReference);
			}
		}
	}
}